const Router = require('koa-router')
const jwt = require('koa-jwt')
const router = new Router({ prefix: '/questions' })
const {
  checkQuestionExist,
  checkQuestioner,
  find,
  findById,
  create,
  update,
  delete: del,
  listTopics,
  listQuestionsFollowers
} = require('../controllers/questions')
const { SECRET } = require('../config')
const auth = jwt({ secret: SECRET })
// 获取问题列表
router.get('/', find)
// 获取指定问题
router.get('/:id', checkQuestionExist, findById)
// 新建问题
router.post('/', auth, create)
// 修改指定问题
router.patch('/:id', auth, checkQuestionExist, checkQuestioner, update)
// 删除指定问题
router.delete('/:id', auth, checkQuestionExist, checkQuestioner, del)
// 获取某个问题下的话题列表
router.get('/:id/topics', checkQuestionExist, listTopics)
// 获取某个话题的关注用户列表
router.get('/:id/followers', checkQuestionExist, listQuestionsFollowers)
module.exports = router
